package com.coder.service;


import java.util.List;

import com.coder.dao.WaveDao;
import com.coder.model.WaveThreshold;

public class WaveService {
	
	private WaveDao waveDao = null;
	public WaveDao getWaveDao() {
		return waveDao;
	}
	public void setWaveDao(WaveDao waveDao) {
		this.waveDao = waveDao;
	}
	
	/**将数据库中的数据从初始化为0，范围从200到710，波长间隔为2*/
	public void saveInitWaveDB(){
		for(int i=200;i<=710;i+=2){
			try{
				WaveThreshold wt = new WaveThreshold(i, 0); 
				waveDao.save(wt);
				System.out.println(wt.getWaveVal());
			}catch(Exception e){
				e.printStackTrace();
			}
		}
	}
	
	/**根据波长获取阈值*/
	public float getThresholdByWave(int waveVal) {
		WaveThreshold threshold = null;
		
		try{
			threshold = waveDao.getThresholdByWave(waveVal);
		}catch(Exception e){
			e.printStackTrace();
		}
		return threshold.getThreshold();
	}
	
	/**更新波长的报警阈值,异常交给action处理*/
	public void updateWaveThreshold(int waveVal, float threshold) {
		WaveThreshold wt = new WaveThreshold(waveVal,threshold);
		waveDao.updateWaveThreshold(wt);
	}
	
	/**获取所有的波长的报警值*/
	public List<WaveThreshold> getAllWaveThreshold(){
		List<WaveThreshold> res = null;
		try{
			res = waveDao.getAllWaveThreshold();
		}catch(Exception e){
			e.printStackTrace();
		}
		return res;
	}
	
}
